﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;

namespace RoadTeam.Pub
{
    public class GetObject
    {
        public static object GetObjectFromPage(object t, Control Control)
        {
            foreach (System.Reflection.PropertyInfo p in t.GetType().GetProperties())
            {
                System.Reflection.PropertyInfo pinfo = t.GetType().GetProperty(p.Name);
                object value = new object();
                Returnfactory.factory(p.PropertyType).ForeachControl(p.Name, Control, ref value);
                if (!IsNullableType(p.GetType()) && value == null) continue;
                pinfo.SetValue(t, value, null);
            }
            return t;
        }

        /// <summary>
        /// 判断是否可空类型
        /// </summary>
        /// <param name="theType"></param>
        /// <returns></returns>
        private static bool IsNullableType(Type T)
        {
            return (T.IsGenericType && T.GetGenericTypeDefinition().Equals(typeof(Nullable<>)));
        }
    }
}
